package com.qf.java2207.no3_teamproject_springboot_01.controller;
//须知少时凌云志，曾许人间第一流



import com.qf.java2207.no3_teamproject_springboot_01.common.R;
import com.qf.java2207.no3_teamproject_springboot_01.pojo.SecurityPerson;
import com.qf.java2207.no3_teamproject_springboot_01.service.SecurityPersonService;
import com.qf.java2207.no3_teamproject_springboot_01.vo.LayuiPageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/person")
public class SecurityPersonController {

    @Autowired
    private SecurityPersonService securityPersonService;



    @RequestMapping("/personList")
    //public LayuiPageVo<SecurityPerson> securityPersonPageData(Integer page,Integer limit){
    // 注意 这里的  @RequestParam 不能省略   省略的话就不能获取参数了
    public LayuiPageVo<SecurityPerson> securityPersonPageData(@RequestParam Map<String,Object> params){
        System.out.println(params);
        //return securityPersonService.securityPersonPageData(page,limit);
        return securityPersonService.securityPersonPageData(params);
    }



    // 这个请求  会匹配到 预检请求
    @GetMapping("/deleteSecurityPerson")
    public R deleteSecurityPerson(Integer id){
        //根据Id删除学生信息
        int result = securityPersonService.deleteSecurityPerson(id);
        if(result==1){
            return R.ok();
        }else{
            return R.error();
        }
    }


    @RequestMapping("/updateSecurityPerson")
    public R updateSecurityPerson(SecurityPerson securityPerson){
        System.out.println(securityPerson);

        int result = securityPersonService.updateSecurityPerson(securityPerson);
        if(result==1){
            return R.ok();
        }else{
            return R.error();
        }

    }


    @RequestMapping("/addSecurityPerson")
    public R addSecurityPerson(SecurityPerson securityPerson){
        System.out.println(securityPerson);

        int result = securityPersonService.addSecurityPerson(securityPerson);
        if(result==1){
            return R.ok();
        }else{
            return R.error();
        }

    }


}
